#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define str string
#define all(x) (x).begin(),(x).end()
#define ms(a,t) memset(a,t,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
#define pb push_back
#define fi first
#define se second
const int maxn = 3000+10;
const int mod = 998244353;
const ll INF = 0x3f3f3f3f;
int n,m;
char c[maxn][maxn];
ll num[maxn][maxn],num2[maxn][maxn];
ll sum;
int pre[maxn][maxn],nxt[maxn][maxn];
int len[maxn][maxn],d[maxn][maxn];
int cnt[maxn];
void solve(int lx,int rx,int ly,int ry) {
	if(lx == rx || ly == ry) return;
	ll s = 0;
	if((rx-lx+1) >= (ry-ly+1)) {
		for(int i = ly; i <= ry; i++) {
			for(int j = i+1; j <= ry; j++) {
				num[i][j] = num2[i][j] = 0;
			}
		}
		int mid = (lx+rx)>>1;
		for(int i = ly; i <= ry; i++) {
			int cur = 0;
			for(int j = mid; j >= len[mid][i] && j >= lx; j--)	cnt[nxt[j][i]]++,cur++;
			for(int j = i+1; j <= ry; j++) {
				cur -= cnt[j-1]; 
				if(len[mid][i] >= len[mid][j]) num[i][j] = cur;
			}
			for(int j = mid; j >= len[mid][i] && j >= lx; j--) cnt[nxt[j][i]] = 0;
		}
		for(int i = ly; i <= ry; i++) {
			int cur = 0;
			for(int j = mid; j >= len[mid][i] && j >= lx; j--)	cnt[pre[j][i]]++,cur++;
			for(int j = i-1; j >= ly; j--) {
				cur -= cnt[j+1]; 
				if(len[mid][i] > len[mid][j]) num[j][i] = cur;
			}
			for(int j = mid; j >= len[mid][i] && j >= lx; j--) cnt[pre[j][i]] = 0;
		}
		
		for(int i = ly; i <= ry; i++) {
			int cur = 0;
			for(int j = mid+1; j <= d[mid+1][i] && j <= rx; j++) cnt[nxt[j][i]]++,cur++;
			for(int j = i+1; j <= ry; j++) {
				cur -= cnt[j-1]; 
				if(d[mid+1][i] <= d[mid+1][j]) num2[i][j] = cur;
			}
			for(int j = mid+1; j <= d[mid+1][i] && j <= rx; j++) cnt[nxt[j][i]] = 0;
		}
		for(int i = ly; i <= ry; i++) {
			int cur = 0;
			for(int j = mid+1; j <= d[mid+1][i] && j <= rx; j++) cnt[pre[j][i]]++,cur++;
			for(int j = i-1; j >= ly; j--) {
				cur -= cnt[j+1]; 
				if(d[mid+1][i] < d[mid+1][j]) num2[j][i] = cur;
			}
			for(int j = mid+1; j <= d[mid+1][i] && j <= rx; j++) cnt[pre[j][i]] = 0;
		}
		for(int i = ly; i <= ry; i++) if(c[mid][i] == c[mid+1][i]){
			for(int j = i+1; j <= ry; j++) if(c[mid][j] == c[mid+1][j] && c[mid][i] == c[mid][j]) {
				s += num[i][j] * num2[i][j];
			}
		}
		solve(lx,mid,ly,ry);
		solve(mid+1,rx,ly,ry);
	} else {
		int mid = (ly+ry)>>1;
		for(int i = lx; i <= rx; i++) {
			for(int j = i+1; j <= rx; j++) {
				num[i][j] = num2[i][j] = 0;
			}
		}
		for(int i = lx; i <= rx; i++) {
			int cur = 0;
			for(int j = mid; j >= pre[i][mid] && j >= ly; j--)	cnt[d[i][j]]++,cur++;
			for(int j = i+1; j <= rx; j++) {
				cur -= cnt[j-1]; 
				if(pre[i][mid] >= pre[j][mid]) num[i][j] = cur;
			}
			for(int j = mid; j >= pre[i][mid] && j >= ly; j--) cnt[d[i][j]] = 0;
		}
		for(int i = lx; i <= rx; i++) {
			int cur = 0;
			for(int j = mid; j >= pre[i][mid] && j >= ly; j--)	cnt[len[i][j]]++,cur++;
			for(int j = i-1; j >= lx; j--) {
				cur -= cnt[j+1]; 
				if(pre[i][mid] > pre[j][mid]) num[j][i] = cur;
			}
			for(int j = mid; j >= pre[i][mid] && j >= ly; j--) cnt[len[i][j]] = 0;
		}
		
		for(int i = lx; i <= rx; i++) {
			int cur = 0;
			for(int j = mid+1; j <= nxt[i][mid+1] && j <= ry; j++) cnt[d[i][j]]++,cur++;
			for(int j = i+1; j <= rx; j++) {
				cur -= cnt[j-1]; 
				if(nxt[i][mid+1] <= nxt[j][mid+1]) num2[i][j] = cur;
			}
			for(int j = mid+1; j <= nxt[i][mid+1] && j <= ry; j++) cnt[d[i][j]] = 0;
		}
		for(int i = lx; i <= rx; i++) {
			int cur = 0;
			for(int j = mid+1; j <= nxt[i][mid+1] && j <= ry; j++) cnt[len[i][j]]++,cur++;
			for(int j = i-1; j >= lx; j--) {
				cur -= cnt[j+1]; 
				if(nxt[i][mid+1] < nxt[j][mid+1]) num2[j][i] = cur;
			}
			for(int j = mid+1; j <= nxt[i][mid+1] && j <= ry; j++) cnt[len[i][j]] = 0;
		}
		for(int i = lx; i <= rx; i++) if(c[i][mid] == c[i][mid+1]) {
			for(int j = i+1; j <= rx; j++) if(c[j][mid] == c[j][mid+1] && c[i][mid] == c[j][mid]) {
				s += num[i][j] * num2[i][j];
			}
		}
		solve(lx,rx,ly,mid);
		solve(lx,rx,mid+1,ry);
	}
	sum += s;
}
void Solve() {
	cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		cin >> (c[i]+1);
	}
	for(int j = 1; j <= m; j++) {
		for(int i = 1; i <= n; i++) {
			if(c[i][j] == c[i-1][j]) len[i][j] = len[i-1][j];
			else len[i][j] = i;
		}
		for(int i = n; i >= 1; i--) {
			if(c[i][j] == c[i+1][j]) d[i][j] = d[i+1][j];
			else d[i][j] = i;
		}
	}
	for(int i = 1; i <= n; i++) {
		for(int j = m; j >= 1; j--) {
			if(c[i][j] == c[i][j+1]) nxt[i][j] = nxt[i][j+1];
			else nxt[i][j] = j;
		}
		for(int j = 1; j <= m; j++) {
			if(c[i][j] == c[i][j-1]) pre[i][j] = pre[i][j-1];
			else pre[i][j] = j;
		}
	}
	solve(1,n,1,m);
	cout<<sum<<'\n';
}
int main() {
	freopen("star.in","r",stdin);
	freopen("star.out","w",stdout);
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	Solve();
	return 0;
}
